home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / amigadoslibrary / ungetc.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  1KB  |  51 lines

  1. /* UnGetC.c   V1.1   93-03-03                  */
  2. /* ROM library: "dos.library/UnGetC", (V36+)   */
  3. /* Copyright 1993, Anders Bjerin, Amiga C Club */
  4.  
  5. #include <dos/dos.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. UBYTE *version = "$VER: UnGetC 1.1";
  12.  
  13. int main( int argc, char *argv[] );
  14. int main( int argc, char *argv[] )
  15. {
  16.   BPTR my_file;
  17.   LONG collected;
  18.   LONG actual;
  19.  
  20.  
  21.   /* Open an already existing file: */
  22.   my_file = Open( "RAM:Important.dat", MODE_OLDFILE );
  23.   if( !my_file )
  24.     exit( 20 );
  25.  
  26.   /* Collect a character: */
  27.   collected = FGetC( my_file );
  28.   if( collected == -1 )
  29.   {
  30.     printf( "Could not collect the character! EOF or Error!\n" );
  31.     Close( my_file );
  32.     exit( 21 );
  33.   }
  34.  
  35.   printf("Character: %c\n", collected);
  36.  
  37.   /* Put back the last read character (-1): */
  38.   actual = UnGetC( my_file, -1 );
  39.  
  40.   /* OK? */
  41.   if( actual == 0 )
  42.     printf( "Could not put back the character!\n" );
  43.   else
  44.     printf( "Character successfully put back!\n" );
  45.  
  46.   Close( my_file );
  47.   exit( 0 );
  48. }
  49.  
  50.  
  51.